package driver.events;

import driver.exceptions.SensorException;

/**
 * Encapsulates a robot sensor, allowing for getting a sensor reading whenever
 * needed. The most recent sensor reading will always be stored.
 *
 * @author David Martin
 */
public abstract class Event
{
  // The most recent sensor reading

  private String lastReading;

  /**
   * Initialises the last reading to an empty string. A reference to the driver
   * controller is kept to allow for communicating with the robot directly
   *
   * @param controller the controller that will allow communication with the robot
   */
  public Event()
  {
    lastReading = "";
  }

  /**
   * Gets the Event name e.g. Sound Sensor
   *
   * @return the event name
   */
  public abstract String getEventName();

  public String getSafeEventName()
  {
    return getEventName().replace(' ', '_').toLowerCase();
  }

  /**
   * Gets the most recent sensor reading, stored locally, without having to
   * communicate with the robot
   *
   * @return the last sensor reading
   */
  public String getLastReading()
  {
    return lastReading;
  }

  /**
   * This method overrides the lastReading variable to the latest sensor reading
   * and returns the value
   *
   * @return the latest sensor reading
   */
  public String getCurrentReading() throws SensorException
  {
    lastReading = readFromSensor();
    return lastReading;
  }

  /**
   * This method should get the latest reading from the sensor, but should not
   * update the lastReading variable (this is done in getCurrentReading())
   *
   * @return the latest sensor reading
   */
  public abstract String readFromSensor() throws SensorException;

  public abstract String getMeasurementUnits();
}
